package testing;

import java.util.HashMap;
import java.util.TreeMap;

public class Sample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for( int i=1;i<=511;i++){
			int sourceFileSize=(512+i)*1024;
			int numberOfSourceFrag=128;
			int fragSize = sourceFileSize/numberOfSourceFrag;
			int optNumberOfFrag=0;
			int modFrag=fragSize%4096;
			int val1 = 0,val2 = 0;
			/*
			 * HashMap<int numSrcFrg, int fragSize> map = new HashMap<K, V>(); 
			 */
			HashMap<Integer, Integer> map1 = new HashMap<Integer, Integer>(); 
			while(modFrag<=2048){
				numberOfSourceFrag++;
				fragSize=sourceFileSize/numberOfSourceFrag;
				modFrag=fragSize%4096;
				map1.put(numberOfSourceFrag, fragSize);
//				System.out.println(" decresing"+numberOfSourceFrag+" "+fragSize);
			}
			sourceFileSize=(512+i)*1024;
			numberOfSourceFrag=128;
			fragSize=sourceFileSize/numberOfSourceFrag;
			modFrag=fragSize%4096;
			HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>(); 
			while(modFrag<2048){
				numberOfSourceFrag--;
				fragSize=sourceFileSize/numberOfSourceFrag;
				modFrag=fragSize%4096;
				map2.put(numberOfSourceFrag, fragSize);
//				System.out.println(" increasing"+numberOfSourceFrag+" "+fragSize);				
			}
			if( !map1.isEmpty()){
				TreeMap<Integer, Integer> decreaseMap= new TreeMap<Integer, Integer>(map1);
				val1=decreaseMap.firstKey();
//				System.out.println(" "+ val1+" "+decreaseMap.get(val1));
			}
			if( !map2.isEmpty()){
			TreeMap<Integer, Integer> increaseMap = new TreeMap<Integer, Integer>(map2);			
			val2=increaseMap.firstKey();
//			System.out.println(" "+val2+" "+increaseMap.get(val2));
			}
			if ( Math.abs(val1-128)< Math.abs(val2-128)){
				optNumberOfFrag=val1;
			}else if (modFrag>2048) {
				optNumberOfFrag=128;
			} else {
				optNumberOfFrag=val2;
			}
			System.out.println(" "+i+" "+optNumberOfFrag);
			//TODO diff the diff between the keys select the difference which is smallest
			
		}
	}

}
